package net.oschina.simpleplus;

import io.grpc.stub.StreamObserver;
import net.oschina.simpleplus.demo.protobuf.model.HelloRequest;
import net.oschina.simpleplus.demo.protobuf.model.HelloResponse;
import net.oschina.simpleplus.demo.protobuf.serv.HelloServiceGrpc;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author simpleplus@sina.cn
 * @since17/5/28下午9:43
 */
public class GreetingServiceImpl extends HelloServiceGrpc.HelloServiceImplBase{
    private static final Logger logger = LoggerFactory.getLogger(GreetingServiceImpl.class);

    @Override
    public void sayHello(HelloRequest request, StreamObserver<HelloResponse> responseObserver) {
        logger.info("rev msg:{},id:{}", request.getName(), request.getId());
        HelloResponse reply = HelloResponse.newBuilder().setMessage(String.format("Hello, %s", request.getName()))
                .build();

        responseObserver.onNext(reply);
        responseObserver.onCompleted();
    }
}
